import 'package:flutterapp/Base/redux/Actions.dart';
import 'package:flutterapp/Base/redux/StateNumCountTest.dart';
import 'package:redux/redux.dart';
import 'package:shared_preferences/shared_preferences.dart';

//初始化redux

class AppState {
  SharedPreferences prefs;
  StateNumCountTest stateNumCountTest;
  static AppState _instance = AppState._();

  static getInstance() {
    return _instance;
  }

  AppState._() {
    _init();
  }

  _init() async {
    prefs = await SharedPreferences.getInstance();
    int count = prefs.getInt('counter') ?? 0;
    stateNumCountTest = new StateNumCountTest(count);
  }
}

AppState reducer(AppState state, action) {
  if (action is ActionNumIncrease) {
    state.stateNumCountTest.totalCount += action.increment;
  }
  return state;
}
